import { HttpClient } from '@angular/common/http';
import { Component, OnInit, Input } from '@angular/core';
import { NameService } from '../name.service';

@Component({
  selector: 'app-my2',
  templateUrl: './my2.component.html',
  styleUrls: ['./my2.component.scss'],
})
export class My2Component implements OnInit {
  name: string;
  data: any;
  @Input() name1: string = 'ss';
  @Input() boss: Boss = { name: '2', age: 12, sex: 1 };
  @Input() getFn: Function = function () {};
  constructor(public nameS: NameService, public http: HttpClient) {
    this.name = '21';
    this.nameS = nameS;
  }

  ngOnInit(): void {}
  ngAfterViewInit(): void {
    //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
    //Add 'implements AfterViewInit' to the class.
    console.log(123);
    this.http
      .get('http://localhost:5001/dev-api/list', {
        params: { a: 1 },
      })
      .subscribe((res) => {
        this.data = res;
      });
    this.http
      .post(
        'http://localhost:5001/dev-api/add',
        { a: 1 },
        {
          headers: {
            token: '123',
          },
        }
      )
      .subscribe((res) => {
        console.log(res);
      });
  }
}
interface data1 {
  msg: string;
  code: number;
}
interface Boss {
  name: string;
  age: number;
  sex: number;
}
